<template>
	<view class="content">
		<view class="padding-about-30 padding-top-30">
			<view class="background">
				<view class="padding-top-30 display-flex space-between">
					<view class="color-FFF margin-left-40 ">
						<view class="font-size-22">
							账户积分
						</view>
						<view class="font-size-36 font-weight-bold">
							{{(user?.all_score * 1) + (user?.score * 1)}}
						</view>
					</view>
					<view @click="navigateTo('/pages/my/Withdrawal')" class="button margin-right-30">
						提现
					</view>
				</view>
				<view class=" margin-top-40">
					<uv-gap height="1" bgColor="#F5F5F5"></uv-gap>
				</view>
				<view class="color-FFF display-flex align-items margin-top-30">
					<view class="font-size-24 margin-left-30">
						累计积分：{{user?.all_score}}
					</view>
					<view class="font-size-24 margin-left-30">
						可用积分：{{user?.score}}
					</view>
				</view>
			</view>
			<view class="margin-top-30 view">
				<view class="display-flex space-between align-items">
					<view @click="datetimePicker.open()" class="time display-flex align-items">
						<view class="file-1 margin-left-10 font-size-22 ">
							{{date}}
						</view>
						<view class="margin-right-10">
							<uv-icon name="arrow-down-fill" color="#2671CE" size="12"></uv-icon>
						</view>
					</view>
					<!-- <view class="time margin-left-30 display-flex align-items">
						<view class="file-1 margin-left-10 font-size-22 ">
							2000-12-21
						</view>
						<view class="margin-right-10">
							<uv-icon name="arrow-down-fill" color="#2671CE" size="12"></uv-icon>
						</view>
					</view> -->
					<view class="font-size-22 margin-left-30">
						<view class="">
							总收入：{{info?.income}}
						</view>
						<view class="">
							总支出：{{info?.expense}}
						</view>
					</view>
				</view>
				<uv-tabs @click="tabs" :list="tabslist" lineWidth="20" :activeStyle="{
			color: '#303133',
			fontWeight: 'bold',
			transform: 'scale(1.05)'
    	}" :inactiveStyle="{
			color: '#606266',
			transform: 'scale(1)'
		}" itemStyle="padding-left: 15px; padding-right: 15px; height: 34px;"></uv-tabs>
				<view class="">
					<view v-for="item,index in list" :key="index" class="">
						<view class="display-flex space-between align-items" style="padding:20rpx 0;">
							<view class="">
								<view class="font-size-26 file-1">
									{{item.memo}}
								</view>
								<view class="font-size-22 margin-top-10 color-999">
									{{timestampToDate(item.createtime * 1000,'Y-m-d')}}
								</view>
							</view>
							<view :style="item.score>=1?'color: #40AD35;':'color: red;'"
								class="margin-right-10 font-size-26">
								{{item.score}}
							</view>
						</view>
						<uv-gap height="1" bgColor="#F5F5F5"></uv-gap>
					</view>
				</view>
			</view>
		</view>
		<uv-datetime-picker ref="year-month" mode="date" :maxDate="Date.now()" @confirm="confirm">
		</uv-datetime-picker>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';
	import {
		onLoad,
		onShow,
		onReady,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		nativeUI,
		navigateTo,
		navigateBack,
		timestampToDate
	} from '@/utils/index.js';
	import * as api from '@/request/app.js'; // 引入api 方法
	import local from '@/utils/localStorage.js'; //引入本地存储方法
	onLoad(function(option) {});
	onShow(function() {});
	const tabslist = ref([{
		name: '全部',
		tab: 'all'
	}, {
		name: '收入',
		tab: 'income'
	}, {
		name: '支出',
		tab: 'expense'
	}])
	const tab = ref('all')
	const date = ref(timestampToDate(Date.now(), 'Y/m/d'))
	const datetimePicker = ref(null)
	//分页
	const pagingState = ref(false)
	const page = ref(1)
	const list = ref([])
	const user = ref()
	const info = ref()
	onLoad(function(option) {
		score_list()
	});
	onShow(function() {});

	function tabs(event) {
		console.log(event);
		tab.value = event.tab
		//分页
		pagingState.value = false
		page.value = 1
		list.value = []
		score_list()
	}

	function confirm(event) {
		console.log(event);
		date.value = timestampToDate(event.value, 'Y/m')
	}
	async function score_list() {
		let object = {
			page: page.value,
			tab: tab.value,
			date: date.value
		}
		if (!pagingState.value) {
			const {
				code,
				data
			} = await api.score_list(object)
			user.value = data.user
			info.value = data
			list.value = list.value.concat(data.list.data)
			if (data.list.current_page == data.list.last_page) {
				pagingState.value = true
				return
			}
			page.value++
		}
	}
	onReady(function() {});
	onReachBottom(function() {
		score_list()
	});
</script>

<style scoped lang="scss">
	.time {
		width: 173rpx;
		height: 66rpx;
		background: #FFFFFF;
		border-radius: 8rpx;
		border: 1px solid #C3DAFC;
	}

	.view {
		padding: 25rpx;
		background: #FFFFFF;
		border-radius: 20rpx;
	}

	.button {
		width: 122rpx;
		height: 42rpx;
		background: #F8F8F7;
		border-radius: 21rpx;
		border: 1px solid #C3DAFC;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 22rpx;
		color: #2671CE;
	}

	.background {
		width: 690rpx;
		height: 240rpx;
		background-size: 100% 100% !important;
		background-repeat: no-repeat;
		background: url('/static/jfbg.png');
	}
</style>